<template>
  <a-modal
      title="查看账号密码"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="dataForm" :model="dataForm">
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="评估人部门">
          {{ dataForm.deptName }}
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="评估人">
          {{ dataForm.username }}
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="评估人手机号">
          {{ dataForm.mobile }}
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账号">
          {{ dataForm.username }}
        </a-form-model-item>
        <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="密码">
          {{ dataForm.password }}
        </a-form-model-item>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { getUserById } from '@/api/api'

export default {
  name: "account-password",
  data() {
    return {
      visible: false,
      confirmLoading: false,
      dataForm: {
        id: '',
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
    }
  },
  methods: {
    init(record) {
      this.visible = true
      this.$nextTick(() => {
        this.confirmLoading = true
        this.dataForm = record
        Promise.all([
          this.getById()
        ]).then(() => {
          this.confirmLoading = false
        }).catch(() => {
          this.visible = false
          this.confirmLoading = false
        })
      })
    },
    getById() {
      return new Promise((resolve, reject) => {
        getUserById(this.dataForm.appraiserId).then(res => {
          if (!res.success) {
            return this.$message.error({
              content: res.message,
              onClose: () => reject()
            })
          }
          let user = res.result
          this.dataForm.username = user.realName
          this.dataForm.mobile = user.mobile
          this.dataForm.username = user.username
          this.dataForm.password = decodeURIComponent(window.atob(user.password2))
          console.log('this.dataForm', this.dataForm)
          resolve()
        }).catch(() => {
          reject()
        })
      })
    },
    handleOk(e) {
      // this.confirmLoading = true;
      // setTimeout(() => {
      this.visible = false;
      //   this.confirmLoading = false;
      // }, 2000);
    },
    handleCancel(e) {
      this.visible = false;
    },
  }
}
</script>

<style scoped>

</style>
